﻿#pragma once

#include <QObject>
#include<qlist.h>
#include<qmap.h>
#include"SongList.h"

class QMediaPlayer;
namespace TagLib {
	class FileRef;
}

class PlaylistManager  : public QObject
{
	Q_OBJECT
public:
	enum ListName
	{
		Default,
		RecentPlaylist
	};

private:

	QStringList m_fileDirs;
	//歌曲列表信息对应扫描添加
	QMediaPlayer* m_adder;
	//当前维护的列表
	SongList* m_curList;
	//所有列表
	QMap<ListName,SongList*> m_allPlayLists;
	ListName m_listType;
	QMutex m_mutex;

	PlaylistManager(QObject* parent = nullptr);

public:
signals:
	//扫描完一部分
	void songsScannedBatch(int begin);
	void songsScannedBatch(const QList<Song>& songs);
	//文件扫描完
	void scanFinished();	

public:
	
	void appendSong(const Song& s);
	~PlaylistManager();
	void appendMusicDir(const QString& dir);
	static PlaylistManager& getInstance();
	QUrl getCurUrl(int index);
	void changeType(PlaylistManager::ListName type);
	//线程不安全
	SongList* getCurSongList();
	//异步扫描歌曲
	void musicFromLocal_Async(int batchSize = 30);

private:
	QString getAudioType(TagLib::FileRef* fileRef);
	//异步添加歌曲信息 - setSource()异步
	void addSongMessage_Async();
};
